<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入要评论的内容(最多评论120字)" name="" id="" maxlength="120"></textarea>
        <mt-button type="primary" size="large">发表评论</mt-button>
        <div class="cmt-list">
            <div class="cmt-item">
                <div class="cmt-title">
                    第一楼&nbsp;用户：匿名用户&nbsp;发表时间:2017-12-12
                </div>
                <div class="cmt-body">
                    他大舅他二舅
                </div>
            </div>



            <div class="cmt-item" v-for="(item, i) in comments" :key="item.add_time">
                <div class="cmt-title">
                    第{{ i+1 }}楼&nbsp;用户：{{ item.user_name }}&nbsp;发表时间:{{ item.add_time | dataFormat}}
                </div>
                <div class="cmt-body">
                    {{ item.content === 'undefined' ? 'use lazy speak nothing' : item.content}}
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    export default {
        data() {
            return {
                pageIndex: 1,
                comments: []
            }
        },
        created(){
            this.getCommets()
        },
        methods: {
            getCommets() {
                this.$http
                    .get("api/getcomments" + this.id + "?pageIndex=" + this.pageIndex)
                    .then(rets => {
                    if (rets.body.status === 0) {
                        this.comments = this.comments.concat(rets.body.message)
                    }else{
                        Toast('failed to get comments')
                    }
                })
            },
            getMore(){
                this.pageIndex++;
                this.getCommets()
            }
        }
    }
</script>

<style lang="scss" scoped>
    .cmt-container {
        margin: 5px;

    h3 {
        font-size: 16px;
    }

    textarea {
        font-size: 14px;
        height: 85px;
        margin: 0;
    }

    .cmt-list {
        margin: 5px;

    .cmt-item {
        font-size: 12px;

    .cmt-title {
        line-height: 24px;
        background-color: #cccccc;
    }

    .cmt-body {
        line-height: 32px;
        text-indent: 2em;
    }

    }
    }
    }
</style>